package com.youhui.weixin.controller.upload;

import org.apache.tomcat.util.http.fileupload.FileItem;
import org.apache.tomcat.util.http.fileupload.FileUpload;
import org.apache.tomcat.util.http.fileupload.FileUploadBase;
import org.apache.tomcat.util.http.fileupload.FileUploadException;
import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by https://github.com/kuangcp on 17-10-7  下午8:44
 */
//public class MultipartListenerResolver extends CommonsMultipartResolver {
//    @Override
//    protected MultipartParsingResult parseRequest(HttpServletRequest request) throws MultipartException {
//        String encoding = determineEncoding(request);
//        FileUpload fileUpload = prepareFileUpload(encoding);
//        //设置监听器
//        fileUpload.setProgressListener(new FileUploadProgressListener(request.getSession()));
//        try {
//            List<FileItem> fileItems = ((ServletFileUpload) fileUpload).parseRequest(request);
//            return parseFileItems(fileItems, encoding);
//        } catch (FileUploadBase.SizeLimitExceededException ex) {
//            throw new MaxUploadSizeExceededException(fileUpload.getSizeMax(), ex);
//        } catch (FileUploadException ex) {
//            throw new MultipartException("Could not parse multipart servlet request", ex);
//        }
//    }
//}
